package org.sy.lab.Java并发编程的艺术.四Java并发编程基础;

import java.util.concurrent.TimeUnit;

import javax.swing.text.html.HTMLDocument.HTMLReader.IsindexAction;

import org.sy.lab.Java并发编程的艺术.SleepUtils;

/**
 * 理解中断
 */
public class Interrupted {
	
	public static void main(String[] args) throws Exception {
		
		Thread sleepThread = new Thread(new SleepRunner(), "SleepThread");
		sleepThread.setDaemon(true);
		
		Thread busyThread = new Thread(new BusyRunner(), "BusyThread");
		busyThread.setDaemon(true);
		
		sleepThread.start();
		busyThread.start();
		
		TimeUnit.SECONDS.sleep(5);
		sleepThread.interrupt();
		busyThread.interrupt();
		
		System.out.println("SleepThread interrupted is" + sleepThread.isInterrupted());
		System.out.println("BusyThread interrupted is" + busyThread.isInterrupted());
		SleepUtils.seccond(2);
	}
	
	static class SleepRunner implements Runnable {
		@Override
		public void run() {
			SleepUtils.seccond(10);
		}
	}
	
	static class BusyRunner implements Runnable {
		@Override
		public void run() {
			while(true);
		}
	}
}
